/**
 * 
 */
package view;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import model.Item;
import model.ManualWeapon;
import model.Upgrade;

import common.ItemFactory;
import common.MessageFactory;

import controller.Controller;

/**
 * @author Bill
 * 
 * This panel is shown on the store panel, and there is one for every available
 * store item. 
 */
public class StoreItemPanel extends SmallItemIconPanel implements MouseListener{
	
	private static final long serialVersionUID = 1L;
	private String itemName;

	public StoreItemPanel(String fileName) {
		super(fileName);
		this.itemName = fileName;
		addMouseListener(this);
	}
	
	public StoreItemPanel(String fileName, String bottomLabel) {
		super(fileName, bottomLabel);
		this.itemName = fileName;
		addMouseListener(this);
	}
	
	public String getItemName(){
		return itemName;
	}

	/**
	 * Mouse events is handled in controller class
	 */
	@Override
	public void mouseClicked(MouseEvent e) {
		Controller.storeItemSelected(this);
		System.out.println(itemName+" was selected");
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		Item item = ItemFactory.createItemFromImageName(itemName);
		if(this.isCovered()) {
			String cost = ""+item.getCost();
			Controller.displayMessage("<html>You need "+cost+" points to buy this item!"+"<br>"+"Earn points by killing more Zombosaurs</html>");
		}
		else Controller.displayMessage(MessageFactory.getItemDescription(item));
	}

	@Override
	public void mouseExited(MouseEvent e) {
		Controller.removeMessage();
	}

	@Override
	public void mousePressed(MouseEvent e) {
		Item item = ItemFactory.createItemFromImageName(itemName);
		if(item instanceof ManualWeapon || item instanceof Upgrade){
			this.highlightItem();
		}
		
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		Item item = ItemFactory.createItemFromImageName(itemName);
		if(item instanceof ManualWeapon || item instanceof Upgrade){
			this.unhighlightItem();
		}
	}

}
